package game;

import game.Config.Config;

import java.util.ArrayList;
import org.newdawn.slick.geom.Vector2f;

/**
 * This class represents a node graph.
 * 
 * @author Sebastian Isheden and Victor Beer
 *
 */
public class NodeGraph {
	private ArrayList<Vector2f> nodes = new ArrayList<Vector2f>();
	int currentNode = 0;
	
	/**
	 * Creates a new NodeGraph with a given start position.
	 * @param startNode The start position.
	 */
	public NodeGraph(Vector2f startNode) {
		this.nodes.add(startNode);
	}
	
	/**
	 * Adds a new node to the graph. The node to be added
	 * must be in tile coordinates.
	 * @param node The node to be added (In tile coordinates).
	 */
	public void addNode(Vector2f node) {
		this.nodes.add(node);
	}
	/**
	 * Returns the next node position, given in "pixel coordinates".
	 * @return The next node, given in "pixel coordinates"
	 */
	public Vector2f getNextNodePosition() {
		Vector2f node = this.nodes.get(currentNode);
		currentNode++;
		return node.copy().scale(Config.TILE_PIXEL_AMOUNT).add(new Vector2f(Config.TILE_PIXEL_AMOUNT/2,Config.TILE_PIXEL_AMOUNT/2));
	}
	/**
	 * Returns if there are more nodes in this graph.
	 * @return True - If this is the last node of the graph. False - If there are more nodes in this graph.
	 */
	public boolean hasNext(){
		if(this.currentNode >= this.nodes.size()){
			return false;
		}
		return true;
	}
	/**
	 * @return	Returns a copy of this graph.
	 */
	public NodeGraph copy(){
		NodeGraph copyGraph = new NodeGraph(this.nodes.get(0).copy());
		for(int i = 1; i<this.nodes.size();i++){
			copyGraph.addNode(this.nodes.get(i).copy());
		}
		return copyGraph;
	}
}
